#coding:utf-8

from PyQt4 import QtGui

from gui import ProfilesDialog 
from include import Utils


class SelectProfilesDialog(QtGui.QDialog):
        def __init__(self,config,root,parent=None):
                super(SelectProfilesDialog,self).__init__(parent)
                self.ui = ProfilesDialog.Ui_Dialog()
                self.ui.setupUi(self)
                self.ui.profilesList.currentIndexChanged.connect(self.main.changeProfile)
                self.mainConfig = config
                sel.rootDir = root
                profiles=Utils.getProfiles(self.rootDir)
                if len(profiles) <= 1:
                        self.ui.profilesList.hide()
                        self.ui.line.hide()
                        self.ui.label.hide()
                else:
                        self.ui.profilesList.show()
                        self.ui.line.show()
                        self.ui.label.show()
                if self.ui.profilesList.count()!=len(profiles):
                        self.ui.profilesList.clear()
                        for profile in profiles:
                                jid = profile.replace("-profile")
                                if self.mainConfig["jid"] == jid:
                                        self.ui.profilesList.addItem(jid,0)
                                else:
                                        self.ui.profilesList.addItem(jid)
                self.ui.profilesList.setCurrenIndex(0)
                